from flask import Blueprint, request
from flask_restful import Api, Resource, marshal_with
from flask_restful.reqparse import RequestParser

from webapp.config import api_utils
from webapp.config.api_utils import oper_log
from webapp.dto_mapper import score_page_fields
from webapp.service.score_service import ScoreService

scorewx_app = Blueprint('scorewx', __name__, url_prefix='/wxapi/score')
scorewx_api = Api(scorewx_app)

parser = RequestParser()
parser.add_argument('id', location='json', type=int, trim=True, required=True)
parser.add_argument('uId', location='json', type=int, trim=True, required=False)
parser.add_argument('sessionId', location='json', type=int, trim=True, required=False)
parser.add_argument('courseId', location='json', type=int, trim=True, required=False)
parser.add_argument('resourceId', location='json', type=int, trim=True, required=False)
parser.add_argument('teachtype', location='json', type=int, trim=True, required=False)
parser.add_argument('score', location='json', type=str, trim=True, required=False)



@scorewx_api.resource("", "/")
class ScoreWxApi(Resource):
    @marshal_with(score_page_fields)
    def get(self):
        params = request.args.items(multi=True)
        params_dict = api_utils.build_params(params)
        return ScoreService.query_all(**params_dict)

@scorewx_api.resource("", "/<int:id>")
class CourseWxApi(Resource):
    @marshal_with(score_page_fields)
    def get(self, id):
        return ScoreService.find_person_score_by_id(id)
